﻿package
{
	import flash.display.MovieClip;
	
	public class Map extends MovieClip {
		private var walkableFields:Array;
		private var goalX:int;
		private var goalY:int;
		private var spawnsX:Array;
		private var spawnsY:Array;
		private var standardPaths:Array;
		private var indexPaths:Array;
		private var felder:Array;
		
		
		
		
		public function Map(fields:Array) {
			felder = fields;
			this.spawnsX = new Array();
			this.spawnsY = new Array();
			this.standardPaths = new Array();
			this.indexPaths = new Array();
			
			walkableFields = new Array(fields.length);

			
			for(var yv:int = 0; yv<fields.length; yv++) {
				walkableFields[yv] = new Array(fields[yv].length);
				
				for(var xv:int = 0; xv<fields[0].length; xv++) {
					var v = fields[yv][xv];
					var feld:MovieClip = new MovieClip();
					switch(v) {
						case 0:
							feld = new Feld();
							break;
						case 1:
							feld = new Feld_MauerLinks();
							break;
						case 2:
							feld = new Feld_MauerRechts();
							break;
						case 3:
							feld = new Feld_MauerOben();
							break;
						case 4:
							feld = new Feld_MauerUnten();
							break;
						case 5:
							feld = new Feld_MauerLinksOben();
							break;
						case 6:
							feld = new Feld_MauerLinksUnten();
							break;
						case 7:
							feld = new Feld_MauerRechtsOben();
							break;
						case 8:
							feld = new Feld_MauerRechtsUnten();
							break;
						case 9:
							feld = new Mauer_FeldLinksOben();
							break;
						case 10:
							feld = new Mauer_FeldLinksUnten();
							break;
						case 11:
							feld = new Mauer_FeldRechtsOben();
							break;
						case 12:
							feld = new Mauer_FeldRechtsUnten();
							break;
						case 13:
							feld = new Mauer();
							break;
						case 20:
							feld = new Falle();
							break;
						case 99:
							feld = new Ziel();
						
						
					}
					this.addChild(feld);
					feld.x = 24 + xv*48;
					feld.y = 24 + yv*48;
					//Feld, TODO: oder Ziel oder Start
					if(feld is Feld)
						walkableFields[yv][xv] = 1;
					else 
						walkableFields[yv][xv] = -1;
						
				}
			}
			
			//createStandardPaths();
		}


		

		
		public function getWalkableFields():Array {
			return this.walkableFields;
		}
		
		public function getHeight():int {
			return this.walkableFields.length;
		}
		
		public function getWidth():int {
			// Muss quadratisch sein! sonst andere Abfrage erstellen
			return this.walkableFields[0].length;
		}

		
		public function getGoalX():int {
			return this.goalX;
		}
		
		public function getGoalY():int {
			return this.goalY;
		}
		
		public function getFields():Array {
			return this.felder;
		}
	}
}